﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KCMS.BusinessLogic.Models;
using KCMS.BusinessLogic.Interfaces;
using StructureMap;

namespace KCMS.Areas.Admin.Controllers
{
    [Authorize]
    public class ContactController : Controller
    {
        private IContactService contactService = ObjectFactory.GetInstance<IContactService>();
        public ActionResult Index()
        {
            var contacts = contactService.getAll();
            return View(contacts);
        }
        [HttpGet]
        public ActionResult Create()
        {
            var contact = new Contact();
            return View(contact);
        }
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult Create(Contact model)
        {
            contactService.save(model);
            return RedirectToAction("Index");
        }
        [HttpGet]
        public ActionResult Edit(Guid id)
        {
            var model = contactService.getById(id);
            return View(model);
        }
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult Edit(Contact model)
        {
            //Contact old = productService.getById(contact.Id);

            //UpdateModel<Contact>(contact);
            contactService.update(model);
            return RedirectToAction("Index");
        }
        [HttpGet]
        public ActionResult Delete()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Delete(Guid id)
        {
            contactService.delete(id);
            return RedirectToAction("Index");
        }

    }
}
